// ATTRIBUTION:
// The fetch category method with variable arguments is courtesy of Matt Gallagher
// http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html
// The modified objectWithURI: method is also from Cocoa with Love
// http://cocoawithlove.com/2008/08/safely-fetching-nsmanagedobject-by-uri.html
// Thanks, Matt

#import <Cocoa/Cocoa.h>

extern NSString* const kSMRUniquePlistKey;


@interface NSManagedObjectContext (SMRAdditions)
-(void)smrDeleteObjects:(NSArray *)objects;
-(NSArray *)smrFetchObjectsForEntityName:(NSString *)newEntityName withPredicate:(id)stringOrPredicate, ...;
-(id)smrFetchFirstObjectForEntityName:(NSString *)newEntityName withPredicate:(id)stringOrPredicate, ...;
-(NSUInteger)smrCountFetchObjectForEntityName:(NSString *)newEntityName withPredicate:(id)stringOrPredicate, ...;
-(NSArray *)smrFetchObjectsForEntityName:(NSString *)newEntityName sortedWithKey:(NSString *)sortKey ascending:(BOOL)ascending withPredicate:(id)stringOrPredicate, ...;
-(NSArray *)smrFetchObjectsForEntityName:(NSString *)newEntityName sortedWithDescriptors:(NSArray *)sortDescriptorsArray withPredicate:(id)stringOrPredicate, ...;

// Return the NSManagedObject associated with the given URI
-(NSManagedObject *)smrObjectWithURI:(NSURL *)uri;

// Return the NSManagedObject associated with the given URI string representation
-(NSManagedObject *)smrObjectWithURIString:(NSString *)uriString;

// Return an array of NSManagedObjects associated with the given URIs
-(NSArray *)smrObjectsWithURIs:(NSArray *)uriArray; 

// Convert the given strings to NSURLs and return their associated NSManagedObjects
-(NSArray *)smrObjectsWithURIStrings:(NSArray *)uriStringArray;

// Load managed objects into the receiver from a plist file.  Top level objects created will be of the given entity.  All objects in the plist file are represented by NSDictionary objects.  Attributes represented by keys in the object's dictionary.  Relationships represented by NSDictionary objects with their own associated properties.  To-many relationships should be arrays of dictionaries.  The key for the dictionary (to-one relationship) or array (to-many relationship) is the property name (top-level dictionary names unused).  Can also use the reserved key "SMRUniquePlistKey" to have the receiver search for an object with the given key and associated value, using the found object (if there is one) as the target of the relationship rather than creating a new one.
-(BOOL)smrLoadObjectsFromURL:(NSURL *)theURL baseEntityName:(NSString *)entityName;

@end
